package kr.co.boogui.actions.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.boogui.actions.ActionHandler;
import kr.co.boogui.service.AdminService;
import kr.co.boogui.service.MemberService;

public class AdminChgPwdAction implements ActionHandler {
	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		String viewPage = "f|/WEB-INF/jsp/admin/admin.jsp";
		String method = req.getMethod();
		if (method.equalsIgnoreCase("get")){
			viewPage = AdminService.adminChk(req, "admin_chgpwd");
		} else if (method.equalsIgnoreCase("post")) {
			if (MemberService.chkPwdService(req)) {				
				if( MemberService.changePwdService(req)) {
					req.setAttribute("action", "admin_chgpwd.jsp");
					req.setAttribute("chg", "y");
					req.setAttribute("result", "success");
				} else {
					req.setAttribute("result", "fail");
				}
			} else {
				req.setAttribute("result", "wrong");
			}
		}		
		
		return viewPage;
	}
}
